<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>home (UsersController)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File users_controller.rb, line 107</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">home</span>  
                <span class="ruby-ivar">@user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">id</span>)
                <span class="ruby-ivar">@title</span> = <span class="ruby-value str">'Home de '</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">+</span> <span class="ruby-value str">' '</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">lastname</span>
                <span class="ruby-ivar">@friendship</span> = <span class="ruby-constant">Friendship</span>.<span class="ruby-identifier">new</span>
                <span class="ruby-ivar">@on_trips</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>]).<span class="ruby-identifier">on_trip</span>
                <span class="ruby-ivar">@trips</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>]).<span class="ruby-identifier">trip</span>
                <span class="ruby-identifier">friendships</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>]).<span class="ruby-identifier">a_users</span>
                <span class="ruby-ivar">@friends</span> = []
                <span class="ruby-identifier">friendships</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">friend</span><span class="ruby-operator">|</span>
                        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">friend</span>.<span class="ruby-identifier">status</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
                                <span class="ruby-ivar">@user_friend</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">friend</span>.<span class="ruby-identifier">user_b_id</span>)
                                <span class="ruby-ivar">@friends</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-ivar">@user_friend</span>
                        <span class="ruby-keyword kw">end</span>
                <span class="ruby-keyword kw">end</span>
                <span class="ruby-identifier">all_users</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">all</span>
                <span class="ruby-ivar">@available_friends</span> = []
                
                <span class="ruby-identifier">friends</span> = []
                <span class="ruby-identifier">friendships</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">friend</span><span class="ruby-operator">|</span>
                        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">friend</span>.<span class="ruby-identifier">status</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">friend</span>.<span class="ruby-identifier">status</span> <span class="ruby-operator">==</span> <span class="ruby-value">2</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">friend</span>.<span class="ruby-identifier">status</span> <span class="ruby-operator">==</span> <span class="ruby-value">3</span>
                                <span class="ruby-ivar">@user_friend</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">friend</span>.<span class="ruby-identifier">user_b_id</span>)
                                <span class="ruby-identifier">friends</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-ivar">@user_friend</span>
                        <span class="ruby-keyword kw">end</span>
                <span class="ruby-keyword kw">end</span>
                
                <span class="ruby-identifier">all_users</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">users</span><span class="ruby-operator">|</span>
                        <span class="ruby-identifier">is_friend</span> = <span class="ruby-keyword kw">false</span>
                        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">users</span>.<span class="ruby-identifier">id</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">id</span>
                                <span class="ruby-identifier">friends</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">friend</span><span class="ruby-operator">|</span>                    
                                        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">users</span>.<span class="ruby-identifier">id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">friend</span>.<span class="ruby-identifier">id</span>
                                                <span class="ruby-identifier">is_friend</span> = <span class="ruby-keyword kw">true</span>
                                        <span class="ruby-keyword kw">end</span>                                        
                                <span class="ruby-keyword kw">end</span>
                        <span class="ruby-keyword kw">else</span>
                                <span class="ruby-identifier">is_friend</span> = <span class="ruby-keyword kw">true</span>
                        <span class="ruby-keyword kw">end</span>
                        <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">is_friend</span>
                                <span class="ruby-ivar">@available_friends</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">users</span>
                        <span class="ruby-keyword kw">end</span>
                <span class="ruby-keyword kw">end</span>
                
                <span class="ruby-ivar">@pending_notifications</span> = []
                <span class="ruby-identifier">friend_ships</span> = <span class="ruby-identifier">friend_ships</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>]).<span class="ruby-identifier">a_users</span>
                <span class="ruby-identifier">friend_ships</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">notification</span><span class="ruby-operator">|</span>
                        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">notification</span>.<span class="ruby-identifier">status</span> <span class="ruby-operator">==</span> <span class="ruby-value">3</span>
                                <span class="ruby-ivar">@user_friend</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">notification</span>.<span class="ruby-identifier">user_b_id</span>)
                                <span class="ruby-ivar">@pending_notifications</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-ivar">@user_friend</span>
                        <span class="ruby-keyword kw">end</span>
                <span class="ruby-keyword kw">end</span>
  <span class="ruby-keyword kw">end</span></pre>
</body>
</html>